<template>
  <div class="myContainer">
    <!-- 头部标题 start -->  
    <el-row class="myHeadeTitle">
      <el-col :span="18" class="myLineHeight_35px">
        设备房管理
      </el-col>
      <el-col :span="6" class="myTextAlignRight">
        <el-button type="primary" class="myBgGreen" @click="add" v-if="isShow(223)">新 增</el-button>
        <!-- <el-button type="primary" class="myBgGreen">导 入</el-button>
        <el-button type="primary" class="myBgGreen">导 出</el-button> -->
      </el-col>
    </el-row>
    <!-- 头部标题 end -->
    <!-- 搜索部分 start -->
    <el-row :gutter="10">
      <el-col :span="6">
        <template>
         <el-cascader
          placeholder="全部项目/小区"
          :options="regionOptions"
          v-model="regionOptSelected"
         ></el-cascader>
        </template>
      </el-col>
      <el-col :span="6">
        <el-input placeholder="输入关键字进行查询" v-model="kw"></el-input>
      </el-col>
      <el-col :span="6">
        <el-button class="myBgGreen" @click="onSearchKW">查询</el-button>
      </el-col>
    </el-row>
    <!-- 搜索部分 end -->
    <!-- 数据列表 start -->
    <div class="myPaddingTop_10px">
      <template>
        <el-table
          v-loading="loading"
          :data="list"
          border
          @selection-change="handleSelectionChange"
          style="width: 100%">
          <el-table-column
            type="selection"
            width="100">
          </el-table-column>
          <el-table-column
            type="index"
            label="序号"
            width="100">
          </el-table-column>
          <el-table-column
            prop="dev_room_no"
            width="120"
            label="设备房编号">
          </el-table-column>
          <el-table-column
            prop="dev_room_name"
            label="设备房名称">
          </el-table-column>
          <el-table-column
            prop="dev_room_type"
            label="设备房类型">
            <template scope="scope">
              <span>{{scope.row.dev_room_type| devRoomType}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="display_room_name"
            label="物理地址">
          </el-table-column>
          <el-table-column
            prop="duty_user_name"
            width="120"
            label="责任人">
          </el-table-column>
          <el-table-column
            prop="status"
            width="100"
            label="设备房状态">
            <template scope="scope">
              <span>{{scope.row.status| deviceStatus}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="area_name"
            label="所属小区">
          </el-table-column>
          <el-table-column
            width="100"
            label="功能操作">
            <template scope="scope">
              <el-button @click="getDetail(scope.row.dev_room_id)" class="look" type="text" size="small">详细</el-button> |
              <el-button @click="modify(scope.row.dev_room_id)" class="look" type="text primary" size="small" v-if="isShow(224)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <!-- 数据列表 end -->
    <!-- 分页控件 start -->
    <div class="block">                    
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page_num"
        :page-sizes="[10, 15]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <!-- 分页控件 end -->
  </div>
</template>  

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myHeadeTitle{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    padding-bottom: 5px;
    border-bottom: 1px solid #dbdbdb;
    margin-bottom:10px; 
  }
  .myHeadeTitle:before,.myHeadeTitle:after{
    content: " ";
    display: block;
    clear: both;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top: 2px;
  }
  .myLineHeight_35px{
    line-height: 35px;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }  
</style>

<script>
 
import { extractAreaIds } from '@/utils/misc';
import { getDevRoomList, devRoomTypeList } from '@/api/dev_room';
import { getRegion } from '@/utils/localstorage';
  export default {
     data(){
      return{
        loading: false,
        list: [],

        regionOptions: [],
        regionOptSelected: [],

        page_size:10,
        page_num:1,
        total:null,
        kw:""
      }
    },
    created(){
      document.title="设备房管理";
      this.regionOptions = getRegion();
      this.regionOptSelected.push(this.regionOptions[0].value,this.regionOptions[0].children[0].value,this.regionOptions[0].children[0].children[0].value);
      
      this.fetchList();
    },    
    computed: {
      areaIds() {
        return extractAreaIds(this.regionOptSelected, this.regionOptions);
      }
    },
    filters: {
      devRoomType: function(value) {
        return devRoomTypeList[value];
      }
    },
    methods:{
       fetchList() {
        this.loading = true;
        let vm = this;
        let params = {
          kw: this.kw,
          page_num: this.page_num,
          page_size: this.page_size
        }; 
        getDevRoomList(this.areaIds, params)
        .then(response => {
          let res = response.data;
          vm.list = res.rows;
          vm.total = res.total;
          vm.page_num = res.page_num;
          vm.page_size = res.page_size;

          vm.loading = false;
        }).catch(error => {
          vm.loading = false;
        })
      },
      onSearchKW() {
        this.fetchList();
      },
      handleSelectionChange(){

      },
      handleSizeChange(val) {//每页条数控制
        this.page_size = val;
        this.fetchList();
      },
      handleCurrentChange(val) {//每页
        this.page_num = val;
        this.fetchList();
      },
      add(){
        this.$router.push({
          path: '/sbjcsjComonents',
          query: {type: 'add'}
        })
      },
      modify(id){
        this.$router.push({
          path:'/sbjcsjComonents',
          query: {type: 'update', id: id}
        })
      },
      getDetail(id){
        this.$router.push({
          path:'/sbjcsjComonents',
          query: {type: 'info', id: id}
        })
      }
    }

  }

</script>  



